home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / appkit.430 < prev    next >
Text File  |  1992-02-06  |  1KB  |  56 lines

  1. {\rtf0\ansi{\fonttbl\f2\fnil Times-Roman;\f1\fmodern Courier;}
  2. \paperw12920
  3. \paperh7040
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520\f2\b0\i0\ul0\fs28 Text object Runs\
  8. \
  9. Q: How do I get at the list of runs in a Text object, without subclassing the Text class?  Once I have them, how do I determine how many of them there are?\
  10.  
  11. \b For 1.0
  12. \b0 \
  13. A: You can cheat and do\
  14. \
  15.     id someText;\
  16.     int nRuns;\
  17.     struct TextStruct \{@defs(Text);\};\
  18. \
  19.     printf ("runs are %x\\n", ((struct TextStruct *)someText)->theRuns);\
  20.     nRuns = theRuns->chunk.used / sizeof(NXRun);\
  21. \
  22. If you're going to use it often enough, you can create a typedef.  Despite this being "cheating," it is supported in Objective-C.\
  23. \
  24.  
  25. \b For 2.0:
  26. \b0 \
  27.  
  28. \pard\tx520\tx1060\tx1600\tx2120\tx2660\tx3200\tx3720\tx4260\tx4800\tx5320\fc0 #import <appkit/Text.h>\
  29. \
  30. @interface Text(Private)\
  31. - (int)nRuns;\
  32. @end\
  33. \
  34. @implementation Text(Private)\
  35. -(int)nRuns\
  36. \{\
  37.     return theRuns->chunk.used/sizeof(NXRun);\
  38. \}\
  39. @end\
  40. \
  41. main ()\
  42. \{\
  43.     id text = [[Text alloc]\
  44.     initFrame:NULL text:"Hello there" alignment:NX_LEFTALIGNED];\
  45.     printf("there are %d runs.\\n", [text nRuns]);\
  46. \}\
  47.  
  48. \pard\tx1140\tx2300\tx3440\tx4600\tx5760\tx6900\tx8060\tx9200\tx10360\tx11520 \
  49. \
  50. QA430\
  51. \
  52. Valid for 1.0\
  53. Valid for 2.0 (see differences noted)\
  54. \
  55.  
  56.